<?php
	/*INDUSTRY'S PROBLEM INDUSTRY'S PROBLEM INDUSTRY'S PROBLEM INDUSTRY'S PROBLEM INDUSTRY'S PROBLEM INDUSTRY'S PROBLEM INDUSTRY'S PROBLEM INDUSTRY'S PROBLEM INDUSTRY'S PROBLEM INDUSTRY'S PROBLEM INDUSTRY'S PROBLEM INDUSTRY'S PROBLEM INDUSTRY'S PROBLEM INDUSTRY'S PROBLEM INDUSTRY'S PROBLEM INDUSTRY'S PROBLEM INDUSTRY'S PROBLEM INDUSTRY'S PROBLEM */
	/*INDUSTRY'S PROBLEM INDUSTRY'S PROBLEM INDUSTRY'S PROBLEM INDUSTRY'S PROBLEM INDUSTRY'S PROBLEM INDUSTRY'S PROBLEM INDUSTRY'S PROBLEM INDUSTRY'S PROBLEM INDUSTRY'S PROBLEM INDUSTRY'S PROBLEM INDUSTRY'S PROBLEM INDUSTRY'S PROBLEM INDUSTRY'S PROBLEM INDUSTRY'S PROBLEM INDUSTRY'S PROBLEM INDUSTRY'S PROBLEM INDUSTRY'S PROBLEM INDUSTRY'S PROBLEM */
	/*INDUSTRY'S PROBLEM INDUSTRY'S PROBLEM INDUSTRY'S PROBLEM INDUSTRY'S PROBLEM INDUSTRY'S PROBLEM INDUSTRY'S PROBLEM INDUSTRY'S PROBLEM INDUSTRY'S PROBLEM INDUSTRY'S PROBLEM INDUSTRY'S PROBLEM INDUSTRY'S PROBLEM INDUSTRY'S PROBLEM INDUSTRY'S PROBLEM INDUSTRY'S PROBLEM INDUSTRY'S PROBLEM INDUSTRY'S PROBLEM INDUSTRY'S PROBLEM INDUSTRY'S PROBLEM */
	/*INDUSTRY'S PROBLEM INDUSTRY'S PROBLEM INDUSTRY'S PROBLEM INDUSTRY'S PROBLEM INDUSTRY'S PROBLEM INDUSTRY'S PROBLEM INDUSTRY'S PROBLEM INDUSTRY'S PROBLEM INDUSTRY'S PROBLEM INDUSTRY'S PROBLEM INDUSTRY'S PROBLEM INDUSTRY'S PROBLEM INDUSTRY'S PROBLEM INDUSTRY'S PROBLEM INDUSTRY'S PROBLEM INDUSTRY'S PROBLEM INDUSTRY'S PROBLEM INDUSTRY'S PROBLEM */
	/*INDUSTRY'S PROBLEM INDUSTRY'S PROBLEM INDUSTRY'S PROBLEM INDUSTRY'S PROBLEM INDUSTRY'S PROBLEM INDUSTRY'S PROBLEM INDUSTRY'S PROBLEM INDUSTRY'S PROBLEM INDUSTRY'S PROBLEM INDUSTRY'S PROBLEM INDUSTRY'S PROBLEM INDUSTRY'S PROBLEM INDUSTRY'S PROBLEM INDUSTRY'S PROBLEM INDUSTRY'S PROBLEM INDUSTRY'S PROBLEM INDUSTRY'S PROBLEM INDUSTRY'S PROBLEM */
	include "../db.php";
	session_start();
	$current_user_id = $_SESSION['user_id'];
	$current_user_username = $_SESSION['username'];
	$username = "";
	if(!isset($_SESSION['user_id'])) {
		session_destroy();
		header("location:../login/login.php?msg=line_13");
	}
	$username2 = $_SESSION['username'];
	$q = "select * from team where leader_id = '$username2'";
	$rs = mysql_query($q);
	if(!$rs) echo mysql_error();
	$team = "Select Team<br />";
	if(($row=mysql_fetch_assoc($rs))!=NULL)
	{
		$team = $team."<input type='radio' id='one' name='one' value='".$row['name']."' />".$row['name']."<br />";
	}
	while(($row=mysql_fetch_assoc($rs))!=NULL)
	{
		$team = $team."<input type='radio' id='one' name='one' value='".$row['name']."' />".$row['name']."<br />";
	}
	$team = $team."<input type='button' value='Add Problem' onclick='return add_student_industry_problem_ajax(guide123)' /><label id='err_guide'></label>";
?>
<head>
<?php 
	include "../scripts/scripts.php"; 
?>

<script>
var team;
function set(id) {
	document.getElementById('lbl1').innerHTML = id;
}
function fetch_team()
	{
	//document.getElementById('err_guide').innerHTML = ""; //To empty the label after empty guide entry : Not working currently
	//document.getElementById(id).value = "Nisarg Mehta";
	var xmlhttp;
	
	if (window.XMLHttpRequest)
	{// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	}
	else
	{// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	
	xmlhttp.onreadystatechange=function()	
	{
		if(xmlhttp.readyState==4 && xmlhttp.status==200)
		{
			//document.getElementById('teams').innerHTML=xmlhttp.responseText;
			//document.getElementById('team_of_student').innerHTML=xmlhttp.responseText;
			//team = xmlhttp.responseText;
		}
		//document.getElementById('lbl1').innerHTML = xmlhttp.responseText;
		//document.getElementById(id).value=xmlhttp.responseText;
	}
	xmlhttp.open("GET","all_team_of_student_ajax.php",true);
	xmlhttp.send();
	}
$(function() {
		$( "#accordion" ).accordion({
		heightStyle: "content"
		});
		
	});
	$(function() {
    $( "input[type=submit], button" )
      .button()
      .click(function( event ) {
        //event.preventDefault();
      });
  });
  //$(function() {
  //function set(id) {
  //document.getElementById('oneone').innerHTML = "niasrg mehta";
  var code = 1;
  var menu;
  $(function() {
	$(".select")
        .button({
          text: true,
          icons: {
            secondary: "ui-icon-triangle-1-s"
          }
        })
        .click(function() {
          menu = $( this ).parent().next().show().position({
            my: "left",
            at: "left bottom",
            of: this
          });
		  $( document ).one( "click", function() {
            //if(code==1) {
				//menu.hide();
			//	code = 0;
			//}
			//else {
			//	code = 1;
				//document.getElementById('oneone').innerHTML = code.value;
			//}
          });
          return false;
        })
        .parent()
          .buttonset()
          .next()
            .hide()
            .menu();
	//}
  });
  var count = 0;
  function close_team_menu()
  {
  	menu.hide();
  }

/* ######################################################################################### */

/* ######################################################################################### */

function add_student_industry_problem_ajax(id)   /* THESE FILES ARE COPIED FROM all_team_of_student_ajax.php */
	{
	var xmlhttp;
	try {
	var problem_id = document.getElementById('lbl1').innerHTML;
	var guide_id = document.getElementById('guide123').value;
	}
	catch(err) {
		
	}
	if(guide_id.length==0) {
		document.getElementById('err_guide').innerHTML = "<font color='red'>Please insert Guide Name</font>";
		return;
	}
	var radios = document.getElementsByName("one");
		for (var i = 0; i < radios.length; i++) {
			if (radios[i].checked) {
				team_id = radios[i].value;
				break;
			}
		}
		if(i>radios.length) {
			document.getElementById('err_guide').innerHTML = "<font color='red'>Please Select a Team</font>";
			return;
		}
	if (window.XMLHttpRequest)
	{// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	}
	else
	{// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function()	
	{
		if(xmlhttp.readyState==4 && xmlhttp.status==200)
		{
			alert(xmlhttp.responseText);
		}
		//document.getElementById('lbl1').innerHTML = xmlhttp.responseText;
		//document.getElementById(id).value=xmlhttp.responseText;
	}
	xmlhttp.open("GET","add_student_industry_problem_ajax.php?problem_id="+problem_id+"&guide_id="+guide_id+"&team_id="+team_id,true);
	xmlhttp.send();
	}
	/* ######################################################################################### */
	/* copied from all_team_of_student_ajax.php*/

		var src;
		var src1 = new Array();
		xmlhttp=new XMLHttpRequest();
		xmlhttp.onreadystatechange=function()	
		{
			if(xmlhttp.readyState==4 && xmlhttp.status==200)
			{
				src = xmlhttp.responseText;
				src1 = src.split(",");
				document.getElementById('lbl1').innerHTML = "";
				
				try {
					//document.getElementById('guide123').value = "This is text box";
				}
				catch(err) {
				
				}
				
				$( "#guide123" ).autocomplete({
					source: src1
				});
			}
		}
		xmlhttp.open("GET","../project/list_of_all_guides.php",true);
		xmlhttp.send();
	/* ######################################################################################### */
	
  
</script>
<link >
<style>
            .divTable
            {
                display:  table;
                width:auto;
                /*background-color:#eee;*/
                /*border:1px solid  #666666;*/
                border-spacing:10px;/*cellspacing:poor IE support for  this*/
                /* border-collapse:separate;*/
                border : 5px solid #859E89;
                border-radius : 0px;
                background : #CFE8D3;
            }

            .divRow
                {
                     display:table-row;
                    width:auto;
                border:2px solid  #666666;
                }
            .divCell_info
                {
                    float:left;/*fix for  buggy browsers*/
                    display:table-column;
                       width:170px;
                    background-color:;
                padding-top: 5px;
				border:2px solid  #666666;
                }
            .divCell_input
                {
                    float:left;/*fix for  buggy browsers*/
                    display:table-column;
                       <!-- width:250px; -->
                    background-color:;
                border:2px solid  #666666;
                }
            .divCell_error
                {
                    float:left;/*fix for  buggy browsers*/
                    display:table-column;
                    width:200px;
                    background-color:;
					border:2px solid  #666666;
                padding: 5px 5px;
                }
            input.rounded
            {
                border: 3px solid #859E89;
                -moz-border-radius: 0px;
                -webkit-border-radius: 0px;
                border-radius: 0px;
                padding: 4px 7px;
            }
	</style>
</head>
<body onLoad='return fetch_team()' name='no'>
<div class='divCell_input' style='width:15%;height:100%'>
	<div class='divCell_input' style='width:100%;height:15%'> 
		<img alt='Profile Picture'></img>
	</div>
	<div class='divCell_input' style='width:100%;height:84%'> 
		<?php 
			include "../left_bottom_navigation.php";
		?>
	</div>
</div>

<div class='divCell_input' style='width:84%;height:15%'>
	abc
</div>

<div class='divCell_input' style='width:84%;height:84%'>
	<?php
		
		$count = 0;
		$accept_content = "";
		$accept = "";
		if(isset($_GET['username'])) {
			echo "<font size='15px'>All Problems of ".$_GET['username']."</font>";
			$username = $_GET['username'];
		}
		else echo "<font size='15px'>All Industry Problems</font>";
		
		if($_SESSION['category']=="student") echo "<input type='text' id='guide123' placeholder = 'Add Guide' style='width:250px;height:30px'/>";
		
		if($username=="") $all_industry_problems_query = "select * from problem where type='IDP'";
		else	$all_industry_problems_query = "select * from problem where added_by = '$username' && type='IDP'";
		$all_industry_problems_rs = mysql_query($all_industry_problems_query);
		/* Set Content of a link */
		
		
		echo "<div id='accordion' style='width:100%' name='no'>";
		while(($all_industry_problems_row=mysql_fetch_assoc($all_industry_problems_rs))!=NULL)
		{
			$count = $count + 1;
			
			$problem_id = $all_industry_problems_row['id'];
			$problem_statement = $all_industry_problems_row['statement'];
			$description = $all_industry_problems_row['description'];
			$available_since = $all_industry_problems_row['doc'];
			$doc = $all_industry_problems_row['doc'];
			$taken = $all_industry_problems_row['taken'];
			$leader_id = $all_industry_problems_row['leader_id'];
			
			if($_SESSION['category']=="student") $accept = "<a href='#' id='$problem_id' >Accept</a>";
			else $accept = "0"; 
			
			if($leader_id==$_SESSION['username'] && $_SESSION['category']=="student") $accept = "1";
			//else
			
			
			$taken1 = "";
			if($taken==0) $taken1 = "No Teams";
			else $taken1 = "$taken Teams";
			
			if(isset($_GET['username'])) $industry = "";
			else	$industry = $all_industry_problems_row['added_by']." : ";
			
			echo "
				<div name='no'>
					$count. $industry $problem_statement
				</div>
				<div name='no' >
					Description : $description <br />
					Available Since : $doc <br />
					Taken by : $taken1 <br />";
					
					if($accept=="0") {}
					else if($accept==1 && $leader_id==$_SESSION['username']) echo "<font color='blue'>Taken by your team</font>";
					else {
					echo "
					<div>
						<button class='select' name='one_one' value='' onClick='return set($problem_id)'>Accept</button>
					</div>					
					<div>
						<label id='teams' name='one_two'>$team</label>
					</div>
					<input type='button' value='Close' onclick='return close_team_menu()'/>";
					}
					echo "
						</div>
			";
		}
	?>
	</div>
</div>
<label id='lbl1'></label>
</body>